﻿Ext.define('SmartClient.view.LoginView',
   {
      extend: 'Ext.form.Panel',
      controller: 'SmartClient.controller.LoginController',

      // Fields will be arranged vertically, stretched to full width
      layout: 'anchor',
      defaults: {anchor: '100%'},

      title: 'Account login',
      bodyPadding: 5,
      buttonAlign: 'center',
      titleAlign: 'center',
      width: 300,
      defaultType: 'textfield',

      initComponent: function()
      {
         Ext.applyIf(this,
            {
               items:
               [
                  {
                     itemId: 'userLoginField',
                     fieldLabel: 'Login',
                     allowBlank: false,
                     enableKeyEvents: true
                  },
                  {
                     itemId: 'userPasswordField',
                     fieldLabel: 'Password',
                     allowBlank: true,
                     enableKeyEvents: true
                  }
               ],

               buttons:
                  [
                     {
                        itemId: 'loginButton',
                        text: 'Login',
                        formBind: true, // Only enabled once the form is valid
                        disabled: true
                     }
                  ],

               renderTo: Ext.getBody()
            });

         return this.callParent(arguments);
      },

      listeners:
      {
         afterrender: function (field)
         {
            this.down('textfield').focus(false, 50);
         }
      }
   });